<template>
    <div id="plus">
        <h1>新增页</h1>
        <el-input v-model="name" placeholder="请输入商品名称"></el-input>
        <el-input v-model="photo" placeholder="请输入商品图片地址"></el-input>
        <el-input v-model="price" placeholder="请输入价格"></el-input>
        <el-input v-model="stock" placeholder="请输入库存"></el-input>
        <el-input v-model=" merchandiseSn" placeholder="请输入规格"></el-input>
        <el-input
                style="margin-top: 20px"
                type="textarea"
                :rows="2"
                placeholder="请输入商品描述"
                v-model="textarea">
        </el-input>
        <el-button type="primary" @click="putShop" style="margin-top: 20px">保存</el-button>
    </div>
</template>

<script>
    export default {
        name: "plus",
        data() {
            return {
                name: '',
                photo: '',
                price: '',
                stock: '',
                merchandiseSn: '',
                textarea: '',
                shopList: [],
            }
        },
        created() {
            this.getShop()
        },
        methods: {
            getShop() {
                this.shopList = JSON.parse(localStorage.getItem("shopList"))
                //console.log(this.shopList)
            },
            putShop() {
                if (/[\u4e00-\u9fa5]/gm.test(this.name)&&this.price!="") {
                    var newshop= {
                        brandStoreName: this.name,
                            smallImage: this.photo,
                            vipshopPrice: this.price,
                            stock: this.stock,
                            merchandiseSn: this.merchandiseSn,
                            productName: this.textarea
                    }
                    this.shopList.unshift(newshop)
                    console.log(newshop)
                    alert("增加商品成功")
                    localStorage.setItem('shopList',JSON.stringify(this.shopList))
                    this.$router.push('/admin')
                }else {
                    alert("请输入正确的商品名称")
                }
            }
        }
    }
</script>

<style scoped>
    .el-input {
        margin-top: 10px
    }
</style>
